import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {environment} from '@env/environment';

@Component({
    selector: 'app-myimgupload',
    templateUrl: './myimgupload.component.html',
    styles: [
            `
            :host ::ng-deep .avatar-uploader,
            :host ::ng-deep .avatar-uploader-trigger,
            :host ::ng-deep .avatar {
                width: 150px;
                height: 150px;
                display: block;
            }

            :host ::ng-deep .avatar-uploader {
                display: block;
                border: 1px dashed #d9d9d9;
                border-radius: 6px;
                cursor: pointer;
            }

            :host ::ng-deep .avatar-uploader-trigger {
                display: table-cell;
                vertical-align: middle;
                font-size: 28px;
                color: #999;
            }

            .save-form-button {
                width: 100%;
            }
        `
    ]
})
export class MyimguploadComponent implements OnInit {

    @Output() responseUrl = new EventEmitter();

    avatarUrl: string;
    imgaUrl: string;
    url_img = 'Upload/';
    uploadPath: string;

    constructor() {
    }

    ngOnInit() {
        this.uploadPath = this.url_img + 'simupload';
    }

    handleChange($event) {
        this.imgaUrl = $event['file']['response'];
        this.avatarUrl = environment.SERVER_URL + this.url_img + this.imgaUrl;
        this.responseUrl.emit(this.imgaUrl);

    }

    beforeUpload() {

    }

    setImg(img: string) {
        this.imgaUrl = img;
        this.avatarUrl = environment.SERVER_URL + this.url_img + this.imgaUrl;
    }
}
